home *** CD-ROM | disk | FTP | other *** search
/ Garbo / Garbo.cdr / mac / hypercrd / hc2_x / tcprogud.sit / TC Prog Guide / card_58255.txt < prev    next >
Text File  |  1991-02-27  |  2KB  |  24 lines

  1. -- card: 58255 from stack: in
  2. -- bmap block id: 0
  3. -- flags: 0000
  4. -- background id: 4755
  5. -- name: 
  6.  
  7.  
  8. -- part contents for background part 4
  9. ----- text -----
  10. (mimicking the right-to-left action of the '=' assignment operator).
  11.  
  12. It is important to distinguish among string constants, character arrays, and character pointers variables, all of which are treated as character pointers.  When a character pointer variable is declared, no space is yet allocated for a character array.  Therefore it is appropriate to use the '=' assignment operator to assign to the pointer variable a pointer to a string, but it is unwise to use strcpy() to assign to the unallocated portion of memory initially pointed to by the pointer variable.  On the other hand when a character array is declared, space is allocated for the array elements.  However, an array name is a constant pointer so it may not be assigned to.  Also, in ANSI C it is illegal to assign a new value to a string constant (although TC still allows this):
  13.  
  14.     char  *ptr1, ptr2[80], *ptr3;   /* allocate two character pointers and one array */
  15.     ptr1 = "Hello, world!";               /* ok.  ptr1 now points to the constant string */
  16.     *(ptr1+7) = 'x';                           /* illegal!  Attempts to change 'w' in constant string */
  17.     ptr2 = "Hello, world!";               /* illegal!  ptr2 is a pointer constant, not variable */
  18.     strcpy(ptr3,"Hello, world!");   /* incorrect!  Copies string to unallocated memory */
  19.  
  20.  
  21.  
  22. -- part contents for background part 7
  23. ----- text -----
  24. 195